package com.smartfit;

import java.util.ArrayList;

import com.smartfit.R;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;

public class CompareHistoryAdapter extends ArrayAdapter<String>
{
    //
//    private Activity m_Activity;
    //
	ArrayList<String> m_Histories;
	
	public CompareHistoryAdapter( Context context , int iResourceID , ArrayList<String> list )
	{
		super( context , iResourceID , list );
		
//		m_Activity = context;
		
		m_Histories = new ArrayList<String>();
		m_Histories.addAll( list );
	}

	private class ViewHolder
	{
		TextView id;
	}

	@Override
	public View getView( int position , View view , ViewGroup parent )
	{
		ViewHolder holder = null;

        ViewHolder viewHolder;
        
        // General ListView optimization code.
        if ( view == null )
        {
        	LayoutInflater vi = ( LayoutInflater )getContext().getSystemService( Context.LAYOUT_INFLATER_SERVICE );
            view = vi.inflate( R.layout.compare_history_list , parent , false );
            
            viewHolder = new ViewHolder();
            viewHolder.id = ( TextView )view.findViewById( R.id.compare_history_id );
            
            view.setTag( viewHolder );
        }
        else
        {
            viewHolder = ( ViewHolder )view.getTag();
        }

        String strHistory = m_Histories.get( position );
        
        viewHolder.id.setText( strHistory );
        
        return view;
	}
}
